#include "adx.h"
#include "screen.h"


MyScreen::MyScreen(int num, unsigned long event_mask, bool replace_wm, QObject *parent)
    : QObject(parent)
{
    screenNum = num;
    dpy = display();
	initialized = false;
	init(event_mask, replace_wm);
}

MyScreen::~MyScreen()
{
}

void MyScreen::init(unsigned long event_mask, bool replace_wm)
{
	xroot = QX11Info::appRootWindow(screenNum);

	QDesktopWidget *desktop = QApplication::desktop();
	wmwindow = desktop->screen(screenNum);

	cmap = QX11Info::appColormap(screenNum);
	depth = QX11Info::appDepth(screenNum);
	width = desktop->width();
	height = desktop->height();
	visual = XDefaultVisual(dpy, screenNum);

	// TODO: set WM Manager atom

	XGrabServer(dpy);
	XWindowAttributes attr;
	XGetWindowAttributes(dpy, xroot, &attr);
	XSelectInput(dpy, xroot, attr.your_event_mask | event_mask);
	XUngrabServer(dpy);
	XFlush(dpy);

	initialized = true;
}

bool MyScreen::checkWMAtom(Atom atom)
{
	QString name = QString("WM_S%1").arg(screenNum);
	char *sel = name.toLatin1().data();
	Atom wm_sn_atom = XInternAtom(dpy, sel, FALSE);
	return (wm_sn_atom == atom);
}

void MyScreen::setWMAtom()
{
}


